package com.ktwlsoft.fundmanage.controller.sms;

import com.ktwlsoft.fundmanage.domain.entity.sms.SendSms;
import com.ktwlsoft.fundmanage.payload.BaseResult;
import com.ktwlsoft.fundmanage.payload.ResultType;
import com.ktwlsoft.fundmanage.service.sms.SmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 短信控制器
 *
 * @author Name on 2019/9/6 14:57
 * @version 1.0
 */
@Api(value = "短信", description = "短信，作者：朱和")
@RestController
@RequestMapping("sms")
public class SmsController {

    @Autowired
    private SmsService smsService;

    /**
     * 短信发送
     * @param model 请求参数
     * @return ResponseEntity<Object>
     */
    @ApiOperation(value = "短信发送", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping("sendSms")
    public ResponseEntity<?> sendSms(@RequestBody @Valid SendSms model, BindingResult result){
        if(result.hasErrors()){
            return ResponseEntity.ok(BaseResult.body(model, ResultType.BUSINESS_ERROR).withMessage(result.getFieldError().getDefaultMessage()));
        }
        return ResponseEntity.ok(smsService.sendSms(model));
    }
}